home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr35 / ckp101.zip / CKPACK.CPP < prev    next >
C/C++ Source or Header  |  1993-06-08  |  6KB  |  171 lines

  1. //=============================================================================
  2. //   CKPACK.CPP  --  Quickie to check callers log for need to run PCBPACK
  3. //                   (used for PCBoard 15.0 IDX/NDX updating old doors)
  4. //-----------------------------------------------------------------------------
  5. //   Status:  Released to public domain
  6. //-----------------------------------------------------------------------------
  7. //   Revision history:
  8. //      Sat Jun 05 1993 - v1.00  Robert Vostreys, FTL Sysop, 404-292-8761
  9. //=============================================================================
  10.  
  11. #include "io.h"
  12. #include "stdio.h"
  13. #include "share.h"
  14. #include "stdlib.h"
  15. #include "process.h"
  16. #include "string.h"
  17. #include "ctype.h"
  18.  
  19. //=============================================================================
  20.  
  21. unsigned char *Program="CKPACK v1.00";
  22.  
  23. unsigned char config_file [128]="";  // config file (ascii text, line count)
  24. unsigned char callers_file[128]="";  //   line 1
  25. unsigned char search_for  [128]="";  //   line 2
  26. unsigned char execute     [512]="";  //   line 3
  27. unsigned char exec_str    [512]="";  // (built using %u -- danger!!!)
  28.  
  29. unsigned char confflag[30000]="";    // don't think anyone has that many...
  30.  
  31. //=============================================================================
  32. void syntax(void)
  33.  {
  34.    puts(Program);
  35.    puts("\tUtility to check callers log for PCB15 NDX/IDX packing needed.\n"
  36.         "\tRobert Vostreys, FTL Sysop (404-292-8761; 296-3120; 299-3930)\n"
  37.         "\t*Released to the Public Domain*\n"
  38.         "\n"
  39.         "Syntax:  CKPACK c:\\dir\\ckpack.cfg\n"
  40.         "\n"
  41.         "ckpack.cfg should contain:\n"
  42.         "  Line 1: Full filename of callers log to examine for last user\n"
  43.         "  Line 2: Text to search for in callers log to identify a message left\n"
  44.         "  Line 3: commandline to execute with %u=confnumber when msg been left\n"
  45.         "  WARNING: Only one '%' should be in the line and it should be the %u!\n"
  46.         "\n"
  47.         "  This program has minimal error checking -- use at your own risk!\n"
  48.         "  I'll write a cleaner one if the need remains present much longer.\n"
  49.         "\n"
  50.         "  If calling PCBPACK.EXE, you must be in your \\PCB directory!");
  51.    fcloseall();
  52.    exit(100);
  53.  }
  54.  
  55. //=============================================================================
  56. unsigned int read_callers_log(void) // uses global callers_file; search_for...
  57.  {
  58.    unsigned char buffer[100];
  59.    FILE *fhandle=NULL;
  60.    signed long   offset=0L;
  61.    signed long   len=0L;
  62.    unsigned int  have_something=0;
  63.    unsigned int  in_user=0;
  64.  
  65.    puts("reading callers log...");
  66.    fhandle=_fsopen(callers_file,"rt",SH_DENYNONE);
  67.  
  68.    if (fhandle!=NULL)
  69.     {
  70.       len=filelength(fileno(fhandle));
  71.       offset=len;
  72.  
  73.       // until top of file or break on **** line after gotten into user log
  74.       while (offset>64L)
  75.        {
  76.          offset-=64L;
  77.          fseek(fhandle,offset,SEEK_SET);
  78.          memset(buffer,0,sizeof(buffer));
  79.          fread(buffer,64,1,fhandle);
  80.          if (buffer[0]=='*' && in_user)  break;
  81.          if (buffer[0]!=' ')          continue;
  82.          in_user=1;
  83.  
  84.          strupr(buffer);  // convert to all uppercase
  85.          if (NULL!=strstr(buffer,search_for))  // found search string
  86.           {
  87.             unsigned char *tp=(unsigned char *)memchr(&buffer[0],'(',64);
  88.             if (NULL!=tp) // found a '('
  89.              {
  90.                tp++;
  91.                if (isdigit(*tp))  // has a number in it
  92.                 {
  93.                   unsigned int conf=atoi(tp);   // get as conference number
  94.                   if (conf<sizeof(confflag)-1)  // valid (er, maybe)
  95.                    {
  96.                      confflag[conf]=1;  // flag conference number
  97.                      have_something=1;  // flag we have something to update
  98.                    }
  99.                 }
  100.              }
  101.           }
  102.        }
  103.       fclose(fhandle);
  104.     }
  105.    else
  106.     {
  107.       puts("Failed to open callers:");
  108.       puts(callers_file);
  109.       puts(sys_errlist[errno]);
  110.     }
  111.  
  112.    return(have_something);
  113.  }
  114.  
  115. //=============================================================================
  116. unsigned int main (unsigned int argc, unsigned char *argv[])
  117.  {
  118.    FILE *fhandle=NULL;
  119.  
  120.    if (argc!=2)  syntax();  // no params/too many params = syntax and abort(1)
  121.    strcpy(config_file,argv[1]);
  122.    if (access(config_file,0))  syntax();
  123.  
  124.    // read config file (minimal checking)
  125.    fhandle=fopen(config_file,"rt");
  126.    if (fhandle==NULL)  syntax();
  127.    if (NULL==fgets(callers_file,sizeof(callers_file)-2,fhandle)) syntax();
  128.    if (NULL==fgets(search_for,  sizeof(search_for)-2,  fhandle)) syntax();
  129.    if (NULL==fgets(execute,     sizeof(execute)-2,     fhandle)) syntax();
  130.    fclose(fhandle);
  131.  
  132.    // strip CR off end of incoming
  133.    if (strlen(callers_file)) callers_file[strlen(callers_file)-1]=0;
  134.    if (strlen(search_for))   search_for  [strlen(search_for)-1]  =0;
  135.    if (strlen(execute))      execute     [strlen(execute)-1]     =0;
  136.  
  137.    // make sure incoming wasn't a blank line
  138.    if (!strlen(callers_file)) syntax();
  139.    if (!strlen(search_for))   syntax();
  140.    if (!strlen(execute))      syntax();
  141.  
  142.    // do non-case sensitive search
  143.    strupr(search_for);
  144.  
  145.    // clear confflags
  146.    memset(confflag,0,sizeof(confflag));
  147.  
  148.    // set confflags via read_callers_log() function
  149.    puts(Program);
  150.    if (read_callers_log())
  151.     {
  152.       unsigned int  i=0; //temp
  153.       unsigned char *tp=&confflag[0];
  154.       puts("Executing specified command string for each conference...");
  155.  
  156.       // confflags set.. find conferences
  157.       for (i=0; i<sizeof(confflag); i++, tp++)
  158.        {
  159.          if (*tp)  // this conf needs updating
  160.           {
  161.             sprintf(exec_str,execute,i); // *ICK!* not safe!
  162.             system(exec_str);            // *ICK!* crank up command.com
  163.           }
  164.        }
  165.     }
  166.  
  167.    return(0);  // successful (er, perhaps...)
  168.  }
  169.  
  170. //-----------------------------------------------------------------------------
  171.